package com.example.studentsRoom.controller;


import com.example.studentsRoom.entity.Absent;
import com.example.studentsRoom.form.SearchForm;
import com.example.studentsRoom.service.impl.MoveoutService;
import com.example.studentsRoom.util.ResultUtil;
import com.example.studentsRoom.vo.PageVo;
import com.example.studentsRoom.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/moveout")
public class MoveoutController {

    @Autowired
    private MoveoutService moveoutService;
    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list/{page}/{size}")
    public ResultVo list(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size
    ){
        PageVo list=moveoutService.listPage(page,size);
        return ResultUtil.success(list);
    }

    /**
     * 模糊查询+分页
     * @param searchForm
     * @return
     */
    @GetMapping("/search")
    public ResultVo search(SearchForm searchForm){
        PageVo pageVo=moveoutService.search(searchForm);
        return ResultUtil.success(pageVo);
    }

    @GetMapping("/moveout/{id}/{value}")
    public ResultVo moveout(
            @PathVariable("id") String id,
            @PathVariable("value") String value
    ){
        Boolean moveout = moveoutService.moveout(id, value);
        if (moveout) return ResultUtil.success(null);
        return ResultUtil.failed();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/moveList/{page}/{size}")
    public ResultVo moveList(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size
    ){
        PageVo list=moveoutService.moveList(page,size);
        return ResultUtil.success(list);
    }

    /**
     * 模糊查询+分页
     * @param searchForm
     * @return
     */
    @GetMapping("/moveSearch")
    public ResultVo moveSearch(SearchForm searchForm){
        PageVo pageVo=moveoutService.moveSearch(searchForm);
        return ResultUtil.success(pageVo);
    }

}

